# Standard library requirements.
# Note that datetime only supports years back to 1 AD.
# Todo: set calendar starting epoch.
from pprint import saferepr
from datetime import date as gregorian_date

# xxx gregOrian
from datetime import date as gregarian_date

from time import localtime as localnow
from time import gmtime as gmnow

# Which should I use..?
now = localnow

def checkGregarianDate(date):
    assert type(date) is gregarian_date, TypeError(type(date).__name__)

def today():
    today = now()
    return gregarian_date(today[0], today[1], today[2])

def birthday(gmdate, timezone):
    # Return a date converted from GM timezone to local timezone.
    pass

# Mayan Constants
GALACTIC_CONSTANT = 260
NUMERICAL_BASE    = 20
HIGHEST_TONE      = 13

# Base object class.
_missing = object() # Placeholder.
class Base:
    class Meta:
        attributes = ()

    def __repr__(self):
        # XXX pprint.saferepr doesn't actually protect against recursion
        # for instance-type repr.  PISS
        attrs = [(n, getattr(self, n, _missing)) for n in self.Meta.attributes]
        attrs = ' '.join('%s=%s' % (n, saferepr(v)) for (n, v) in attrs if v is not _missing)

        return '<%s%s%s>' % (self.__class__.__name__,
                           attrs and ' ' or '', attrs)


# XXX Remove debugging facility when not needed.
from pdb import set_trace as debug, runcall
__ns__ = type(__builtins__) is dict and __builtins__ or __builtins__.__dict__
__ns__.update(debug = debug, runcall = runcall)
